Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents | Next |

Determining Current Colors and Best Intermediate Colors

The GetForeColor and GetBackColor procedures allow you to obtain the foreground and background colors for the current graphics port, both basic and color. You can use the GetCPixel procedure to determine the color of an individual pixel. The GetGray function can do more than its name implies: it can return the best gray for a given graphics device, but it can also return the best available intermediate color between any two colors.

GetForeColor

Use the GetForeColor procedure to obtain the color of the foreground color for the current graphics port.

PROCEDURE GetForeColor (VAR color: RGBColor);
color
An RGBColor record.

DESCRIPTION

In the color parameter, the GetForeColor procedure returns the RGBColor record for the foreground color of the current graphics port. This procedure operates for graphics ports defined by both the GrafPort and CGrafPort records. If the current graphics port is defined by a CGrafPort record, the returned value is taken directly from the rgbFgColor field.

If the current graphics port is defined by a GrafPort record, then only eight possible RGB values can be returned. These eight values are determined by the values in a global variable named QDColors , which is a handle to a color table containing the current QuickDraw colors. These colors are listed in Table 4-4 . This default set of colors has been adjusted to match the colors produced on the ImageWriter II printer.

SPECIAL CONSIDERATIONS

This procedure is available for basic QuickDraw only in System 7.

SEE ALSO

You can use the RGBForeColor procedure, described on RGBForeColor , to change the foreground color.

GetBackColor

Use the GetBackColor procedure to obtain the background color of the current graphics port.

PROCEDURE GetBackColor (VAR color: RGBColor);
color
An RGBColor record.

DESCRIPTION

In the color parameter, the GetBackColor procedure returns the RGBColor record for the background color of the current graphics port. This procedure operates for graphics ports defined by both the GrafPort and CGrafPort records. If the current graphics port is defined by a CGrafPort record, the returned value is taken directly from the rgbBkColor field.

If the current graphics port is defined by a GrafPort record, then only eight possible colors can be returned. These eight colors are determined by the values in a global variable named QDColors , which is a handle to a color table containing the current QuickDraw colors. These colors are listed in Table 4-4 .

SPECIAL CONSIDERATIONS

This procedure is available for basic QuickDraw only in System 7.

SEE ALSO

You can use the RGBBackColor procedure, described on RGBBackColor , to change the background color.

GetCPixel

To determine the color of an individual pixel, use the GetCPixel procedure.

PROCEDURE GetCPixel (h,v: Integer; VAR cPix: RGBColor);
h
The horizontal coordinate of the point at the upper-left corner of the pixel.
v
The vertical coordinate of the point at the upper-left corner of the pixel.
cPix
The RGBColor record for the pixel.

DESCRIPTION

In the cPix parameter, the GetCPixel procedure returns the RGB color for the pixel at the location you specify in the h and v parameters.

SEE ALSO

You can use the SetCPixel procedure, described on SetCPixel , to change the color of this pixel.

GetGray

To determine the best intermediate color between two colors on a given graphics device, use the GetGray function.

FUNCTION GetGray (device: GDHandle; backGround: RGBColor;
                                         VAR foreGround: RGBColor): Boolean;
device
A handle to the graphics device for which an intermediate color or gray is needed.
backGround
The RGBColor record for one of the two colors for which you want an intermediate color.
foreGround
On input, the RGBColor record for the other of the two colors; upon completion, the best intermediate color between these two.

DESCRIPTION

The GetGray function determines the midpoint values for the red, green, and blue values of the two colors you specify in the backGround and foreGround parameters. In the device parameter, supply a handle to the graphics device; in the backGround and foreGround parameters, supply RGBColor records for the two colors for which you want the best intermediate RGB color. When GetGray completes, it returns the best intermediate color in the foreGround parameter.

One use for GetGray is to return the best gray. For example, when dimming an object, supply black and white as the two colors, and GetGray returns the best available gray that lies between them. (The Menu Manager does this when dimming unavailable menu items.)

If no gray is available (or if no distinguishable third color is available), the foreGround parameter is unchanged, and the function returns FALSE . If at least one gray or intermediate color is available, it is returned in the foreGround parameter, and the function returns TRUE .


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next